<<<<<<< HEAD
import pygame
import pdb
from Battle import *
pygame.init()
screen = pygame.display.set_mode((1024, 768))
pygame.display.set_caption('background')

player_l = pygame.image.load("Data\Image\Background\link.png")#玩家
player_r = pygame.image.load("Data\Image\Background\link_r.png")#玩家
bgImg1 = pygame.image.load("Data\Image\Background\\village.png")#场景一
bgImg2 = pygame.image.load("Data\Image\Background\\battle.png")#场景二
playerX = 150
playerY = 550
playerStep1 = 0
playerStep2 = 0
Running = True
scene1 = True 
scene2 = False
left = False
right = False
gameState = 2
# 场景渲染和人物渲染，第一个参数表示场景编号，第二个参数表示人物面朝方向
def sceneRender(mapID, action):
    screen.blit(mapID, (0, 0))
    screen.blit(action, (playerX, playerY))
# 人物移动，以及判断出界情况
def playerMove():
    global playerX, playerY, scene1, scene2, playerStep1, playerStep2
    playerX += playerStep1
    playerY += playerStep2
    if playerX > 1024:                  #人物移动范围
      playerX = 50
      scene2 = True
      scene1 = False 
    if playerX < 0:
      playerX = 900
      scene1 = True
      scene2 = False
    if playerY > 600:
      playerY = 600
    if playerY < 400:
      playerY = 400
# 初始化，响应相关键盘操作比如控制移动
def init():
    global playerX, playerY, scene1, scene2, playerStep1, playerStep2, left, right
    sceneRender(bgImg1,player_r)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            Running = False
            pygame.quit()
            pdb.set_trace()
        if event.type == pygame.KEYDOWN:#键盘操作位置
          if event.key == pygame.K_RIGHT:
               playerStep1 = 5
               left = False
               right = True
          elif event.key == pygame.K_LEFT:
               playerStep1 = -5
               left = True
               right = False
          if event.key == pygame.K_UP:
               playerStep2 = -2
          elif event.key == pygame.K_DOWN:
               playerStep2 = 2   
        if event.type == pygame.KEYUP:
               playerStep1 = 0
               playerStep2 = 0
# 场景切换
def checkRander():
    global scene1, scene2, left, right,gameState
    # 第1场——村庄 
    if scene1 and left:
      sceneRender(bgImg1, player_l)
    if scene1 and right:
      sceneRender(bgImg1, player_r)
    # 第2场景 打怪
    if scene2 and left:  
      gameState = 2                         #场景切换
      sceneRender(bgImg2, player_l)
    if scene2 and right: 
      gameState = 2                          
      sceneRender(bgImg2, player_r)

def render():
  global gameState
  # 主程序
  if(gameState == 1):
    while Running:
        # 提取键盘操作一些相关初始化
        init()
        # 人物移动
        if(gameState == 1):
          playerMove()
          # 根据一些已知条件进行场景渲染
          checkRander()
          pygame.display.update()
  if(gameState == 2):
    startBattle()
=======
import pygame
import pdb
from Battle import *
pygame.init()
screen = pygame.display.set_mode((1024, 768))
pygame.display.set_caption('background')

player_l = pygame.image.load("Data\Image\Background\link.png")#玩家
player_r = pygame.image.load("Data\Image\Background\link_r.png")#玩家
bgImg1 = pygame.image.load("Data\Image\Background\\village.png")#场景一
bgImg2 = pygame.image.load("Data\Image\Background\\battle.png")#场景二
playerX = 150
playerY = 550
playerStep1 = 0
playerStep2 = 0
Running = True
scene1 = True 
scene2 = False
left = False
right = False
gameState = 2
# 场景渲染和人物渲染，第一个参数表示场景编号，第二个参数表示人物面朝方向
def sceneRender(mapID, action):
    screen.blit(mapID, (0, 0))
    screen.blit(action, (playerX, playerY))
# 人物移动，以及判断出界情况
def playerMove():
    global playerX, playerY, scene1, scene2, playerStep1, playerStep2
    playerX += playerStep1
    playerY += playerStep2
    if playerX > 1024:                  #人物移动范围
      playerX = 50
      scene2 = True
      scene1 = False 
    if playerX < 0:
      playerX = 900
      scene1 = True
      scene2 = False
    if playerY > 600:
      playerY = 600
    if playerY < 400:
      playerY = 400
# 初始化，响应相关键盘操作比如控制移动
def init():
    global playerX, playerY, scene1, scene2, playerStep1, playerStep2, left, right
    sceneRender(bgImg1,player_r)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            Running = False
            pygame.quit()
            pdb.set_trace()
        if event.type == pygame.KEYDOWN:#键盘操作位置
          if event.key == pygame.K_RIGHT:
               playerStep1 = 5
               left = False
               right = True
          elif event.key == pygame.K_LEFT:
               playerStep1 = -5
               left = True
               right = False
          if event.key == pygame.K_UP:
               playerStep2 = -2
          elif event.key == pygame.K_DOWN:
               playerStep2 = 2   
        if event.type == pygame.KEYUP:
               playerStep1 = 0
               playerStep2 = 0
# 场景切换
def checkRander():
    global scene1, scene2, left, right,gameState
    # 第1场——村庄 
    if scene1 and left:
      sceneRender(bgImg1, player_l)
    if scene1 and right:
      sceneRender(bgImg1, player_r)
    # 第2场景 打怪
    if scene2 and left:  
      gameState = 2                         #场景切换
      sceneRender(bgImg2, player_l)
    if scene2 and right: 
      gameState = 2                          
      sceneRender(bgImg2, player_r)

def render():
  global gameState
  # 主程序
  if(gameState == 1):
    while Running:
        # 提取键盘操作一些相关初始化
        init()
        # 人物移动
        if(gameState == 1):
          playerMove()
          # 根据一些已知条件进行场景渲染
          checkRander()
          pygame.display.update()
  if(gameState == 2):
    startBattle()
>>>>>>> 94cb98322753a8bfa7c40436c4d875db975d48f7
